/* ----------------------------------------------------- */
/* -----          "Time Control" functions         ----- */
/* ----------------------------------------------------- */

function time_control_update(var_name)
{
	var elh  = document.getElementById('id_'+var_name+'_h');
	var elm  = document.getElementById('id_'+var_name+'_m');
	var elam = document.getElementById('id_'+var_name+'_am');
	var elt  = document.getElementById('id_'+var_name);
	
	elt.value = ( elam.value == 0 ? 0 : 12 * 3600 ) +
	            elh.value * 3600 + elm.value * 60;
}  

/* ----------------------------------------------------- */
/* -----         Highligh Example functions        ----- */
/* ----------------------------------------------------- */

var toHex = new Array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');

function intToRGB(v)
{
	if (v < 0) return "";
	
	s = "";
	while (v > 0) {
		d = v % 16;
		v = Math.floor(v / 16);
		s = toHex[d] + s;
	}
	while (s.length < 6) s = '0' + s;
	return "#"+s;
}


/*
Input parameters:
	sp, sp2 - spans (with example) id (we need two spans one in other)
	f_c, bk_c - font and background color (int)
	fs_b, fs_i, fs_u, fs_s - font style options: bold, italic, underline, strike
*/
function update_highlight_example(sp, sp2, spi, spi2, f_c, bk_c, fs_b, fs_i, fs_u, fs_s)
{
	var el = document.getElementById(sp);
	var el2 = document.getElementById(sp2);
	el.style.color = intToRGB(f_c);
	el.style.background = intToRGB(bk_c);
	el.style.fontWeight = (fs_b ? "bold" : "");
	el.style.fontStyle = (fs_i ? "italic" : "");
	el.style.textDecoration = (fs_u ? "underline" : "");
	el2.style.textDecoration = (fs_s ? "line-through" : "");

	var el = document.getElementById(spi);
	var el2 = document.getElementById(spi2);
	el.style.color = intToRGB(f_c ^ 0xffffff);
	el.style.background = intToRGB(bk_c ^ 0xffffff);
	el.style.fontWeight = (fs_b ? "bold" : "");
	el.style.fontStyle = (fs_i ? "italic" : "");
	el.style.textDecoration = (fs_u ? "underline" : "");
	el2.style.textDecoration = (fs_s ? "line-through" : "");
}
